var flagName = false;
var oName = document.getElementById("name");
var oTname = document.getElementById("tname");

oName.onblur = function() {
	$.post("./php/login.php", {
		userName: oName.value
	}).then(function(res) {
		if (res == "0") {
			oTname.innerHTML = "";
			flagName = true;
		} else if (res == "1") {
			oTname.innerHTML = "*用户名不存在";
			flagName = false;
		}
	});
}


var flagPass = false;
var oPassword = document.getElementById("password");
var oTpassword = document.getElementById("tpassword");
oPassword.onblur = function() {
	$.post("./php/login1.php", {
		userName: oName.value,
		userPwd: oPassword.value,
	}).then(function(res) {
		if (res == "0") {
			oTpassword.innerHTML = "";
			flagPass = true;
		} else if (res == "1") {
			oTpassword.innerHTML = "*密码输入错误";
			flagPass = false;
		}
	});
}

var oButton = document.getElementById("button");
oButton.onclick = function() {
	if (flagName == true && flagPass == true) {
		location.href = "./index.html";
		// console.log(oName.value);
		// console.log(oPassword.value);
		jump1();
	} else {
		if (oName.value == "") {
			oTname.innerHTML = "*用户名必填";
		}
		if (oPassword.value == "") {
			oTpassword.innerHTML = "*密码必填";
		}
		return false;
	}
	return false;
}

name = oName.value;
password = oPassword.value;
function jump1() {
	url = "index.html?name=" + name + "&password=" + password; //此处拼接内容
	window.location.href = url;
}
